package map.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import map.Airport;

import core.Graphe;
import core.compagnie.CarteFidelite;
import core.compagnie.TypeCarteFidelite;
import core.dijkstra.DijkstraEngine;
import core.voyageur.Client;
import core.voyageur.Trajet;

import serveur.SimulationServeur;
 
public class FenetreInfoClient extends JFrame implements ActionListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel pan;
	private JButton buttonFermer;
	private JPanel centerPanel;
	private JPanel southPanel;
	private JLabel nom;
	private JLabel prenom;
	private JList listeBillets;
	private JList listeCartes;
	private JScrollPane scrollBillets;
	private JScrollPane scrollCartes;
	private JCheckBox suivre;
	private boolean suivi;
	private Client client;
	
        public FenetreInfoClient(Client c, boolean suivi){

        		int width = 800;
        		int height = 500;
                this.setTitle("Infos Client");
                this.setSize(width, height);
                this.setLocationRelativeTo(null);    
                this.suivi=suivi;
                this.client=c;
               
                
                nom = new JLabel(c.getNom());
                
                prenom = new JLabel(c.getPrenom());
                
                listeCartes = new JList(c.getCartes().toArray());
                listeCartes.setEnabled(false);
                
                scrollCartes = new JScrollPane(listeCartes);
                scrollCartes.setMaximumSize(new Dimension(width-50,120));
                scrollCartes.setVisible(true);
                
                listeBillets = new JList(c.getBillets().toArray());
                listeBillets.setEnabled(false);
                
                scrollBillets = new JScrollPane(listeBillets);
                scrollBillets.setMaximumSize(new Dimension(width-50,120));
                scrollBillets.setVisible(true);
                
                suivre = new JCheckBox("Suivre sur la carte");
                suivre.setSelected(suivi);
                suivre.addItemListener(new ItemState());
               
                
                //Instanciation d'un objet JPanel
                pan = new JPanel();
                pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
                //On prévient notre JFrame que ce sera notre JPanel qui sera son contentPane
                this.setContentPane(pan);
    			
    			buttonFermer = new JButton("Fermer");
    			buttonFermer.setEnabled(true);
    			buttonFermer.addActionListener(this);

    			
    			/* Partie centrale :
    			 * Infos client
    			 */

    			JPanel infosPanel = new JPanel();
    			infosPanel.setLayout(new BoxLayout(infosPanel, BoxLayout.PAGE_AXIS));			
  			   			
    			JPanel jPNom = new JPanel();
    			jPNom.add(new JLabel("Nom :"));
    			jPNom.add(nom, BorderLayout.WEST);
    			
       			JPanel jPPrenom = new JPanel();
       			jPPrenom.add(new JLabel("Prenom :"));
       			jPPrenom.add(prenom, BorderLayout.WEST);
       			   			
       			    			
    			infosPanel.add(jPNom, BorderLayout.WEST);
    			infosPanel.add(jPPrenom, BorderLayout.WEST);
    			infosPanel.add(suivre);
    			infosPanel.add(new JLabel(" "));
    			infosPanel.add(new JLabel("Cartes :"));
    			infosPanel.add(scrollCartes, BorderLayout.WEST);
    			infosPanel.add(new JLabel(" "));
    			infosPanel.add(new JLabel("Billets :"));
    			infosPanel.add(scrollBillets, BorderLayout.WEST);
    					    		
    			centerPanel = new JPanel();
    			centerPanel.add(infosPanel, BorderLayout.WEST);
    			
    			/* Partie basse :
    			 * Bouton fermer
    			 */
        			
    			southPanel = new JPanel();
    			southPanel.add(buttonFermer);
    						

    			pan.add(centerPanel, BorderLayout.WEST);
    			pan.add(southPanel, BorderLayout.SOUTH);
                
                this.setVisible(true);
        }

		public JPanel getPan() {
			return pan;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(e.getActionCommand().equals(buttonFermer.getActionCommand())) {
					this.dispose();
				}
			
			}
		
		
		
		/**
		 * @return the suivi
		 */
		public boolean isSuivi() {
			return suivi;
		}
		
		


		/**
		 * @return the client
		 */
		public Client getClient() {
			return client;
		}




		private class ItemState implements ItemListener {

			@Override
			public void itemStateChanged(ItemEvent e) {
				if(e.getItem().equals(suivre)) {
					suivi = !suivi;
				}
				
			}
			
		}
						
		}

        
        
        
